package com.fanxj.service.impl;

import com.fanxj.domain.User;
import com.fanxj.mapper.AdminMapper;
import com.fanxj.mapper.SuperAdminMapper;
import com.fanxj.mapper.UserMapper;
import com.fanxj.service.SuperAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service("SuperAdminService")
public class SuperAdminServiceImpl implements SuperAdminService {
    @Autowired
    private SuperAdminMapper superAdminMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAllUser() {
        return superAdminMapper.findAllUser();
    }

    @Override
    public List<User> findUserByName(String userName) {
        return superAdminMapper.findUserByName(userName);
    }

    @Override
    public void UpdateRole(User user) {
        superAdminMapper.UpdateRole(user);
    }

    @Override
    public String saveAdmin(User user) {
        //判断数据库中是否已经注册过
        User userExist=userMapper.findByUser(user);
        if(userExist!=null){
            return "exist";
        }
        superAdminMapper.saveAdmin(user);
        return "success";
    }

    @Override
    public List<User> findAdminByName(String userName) {
        return superAdminMapper.findAdminByName(userName);
    }

    @Override
    public void deleteAdmin(User user) {
        superAdminMapper.deleteAdmin(user);
    }


}
